package com.googlecode.trabhci2011.stockmarket.shared;

import java.text.ParseException;
import java.util.Date;

public class StockDataEntry {

	private String index = "";

	private String date = "";
		
	private double open = 0.0;
	
	private double close = 0.0;
	
	private double high = 0.0;
	
	private double low = 0.0;
	
	private double volume = 0.0;
	
	private double adjClose = 0.0;
	
	public StockDataEntry(String data){
		String splits[] = data.split(","); 
		if (splits.length != 8){
			throw new IllegalArgumentException("Invalid input line");
		}
		index = splits[0];
		date = splits[1];
		try {
			open = Double.parseDouble(splits[2]);
			high = Double.parseDouble(splits[3]);
			low = Double.parseDouble(splits[4]);
			close = Double.parseDouble(splits[5]);
			volume = Double.parseDouble(splits[6]);
			adjClose = Double.parseDouble(splits[7]);
		} catch (NumberFormatException e){
			throw new IllegalArgumentException(e);
		}
			
	}

	public String getIndex(){
		return index;
	}
	
	public double getHigh(){
		return high;
	}

	public String getDate(){
		return date;
	}
	
	public String getId(){
		String out = index + "_" + date;
		return out;
	}
	
	

	public String toString() {
		String out = index + ",";
		out += date + ",";
		out += open + ",";
		out += high + ",";
		out += low + ",";
		out += close + ",";
		out += volume + ",";
		out += adjClose;
		return out;
	}
	
}
